
import { Font, Vec3, Node, AudioClip, AnimationClip, sys } from "cc"
import { type Socket } from "../utils/uni-socket.io.js";
import Singleton from "../Base/Singleton"
import { GAME_MODE_ENUM } from "../../Enums"
import { GamePlayer } from "../Role/GamePlayer"
import { DumbEnemy } from "../Npc/DumbEnemy"
import { ChargingEnemy } from "../Npc/ChargingEnemy"
import { HelmetEnemy } from "../Npc/HelmetEnemy"
import { LeapingEnemy } from "../Npc/LeapingEnemy"
import { AudioMgr } from "./AudioMgr"
import seedRandom from "../utils/seedrandom.min.js"
import { GameElement } from "../UI/GameElement"
import { Enemy,LevelInfo, roomInfo } from "../types/type"
import { ControllerManager } from "../UI/ControllerManager.js";
export default class DataManager extends Singleton {
    static get Instance() {
        return super.GetInstance<DataManager>()
    }
    shareNumber:Number|String="" //点击分享按钮获取的房间号
    game_ready:Boolean=false //联机模式下判断双方是不是都进来了
    start_time=0//请求开始时间
    ping_time=0 //网络延时
    delayedNumber:Node=null  //显示延时的node
    seed_random=seedRandom(new Date()) //随机种子
    player: Array<GamePlayer> = [] //当前玩家
    gameElement: GameElement
    explosionTime: number = 10 //爆炸倒计时
    enemyList: Array<DumbEnemy | ChargingEnemy | HelmetEnemy | LeapingEnemy> = [] //当前关卡的所有怪物
    fraction: number = 0 //当前得分
    operationNode: Node //游戏内的弹框数据
    color: string = "#85BEF3" //主题默认颜色
    gameMode: GAME_MODE_ENUM = GAME_MODE_ENUM.SINGLE //游戏模式
    drawerNumber: number = 0 //当前有几个弹框
    disbledButton: Boolean = false //是否禁用按钮
    audioMgr: AudioMgr = null //音频组件
    controllerManager:ControllerManager
    client=undefined as Socket | undefined; // socket连接
    mute: boolean = sys.localStorage.getItem('mute') ? JSON.parse(sys.localStorage.getItem('mute')) : false //是否静音
    fractionNumber:Node // 分数的node
    timeout:number // 记录网络延时的时间
    eatName:string="" //当前吃掉的道具
    current_role:string="" //当前登录账号控制的角色名称

    //素材信息
    blueLeadAssets = { jsonAsset: [], spriteFrame: [] }
    greenLeadAssets = { jsonAsset: [], spriteFrame: [] }
    homeAssets = { jsonAsset: [], spriteFrame: [] }
    mapAssets = { jsonAsset: [], spriteFrame: [] }
    enemyAssets = { jsonAsset: [], spriteFrame: [] }
    audio: AudioClip[] = []
    font: Font[] = []  //字体素材
    fire_clip: AnimationClip = null
    brick_clip: AnimationClip = null
    luker_clip: AnimationClip = null
    jelly_clip: AnimationClip = null
    blast_clip: AnimationClip = null
    luker_frame: Array<Enemy> = []
    dumbEnemyList: Array<Enemy> = []
    chargingEnemyList: Array<Enemy>= []
    helmetEnemyList: Array<Enemy> = []
    leapingEnemyList: Array<Enemy> = []
    // 素材end 

    // 关卡信息
    room:roomInfo=null //房间信息
    record_id:number //游戏记录id
    otherLine:boolean=true //对方是否在线
    levelInfo:LevelInfo={
        levels: [
            // [9, 13, 13, 35, 13, 13, 13, 42, 13, 13, 13, 13, 13, 10],
            // [14, 0, 0, 0, 0, 0, 0, 0, 0,1, 21, 0, 1, 14],
            // [14, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 14],
            // [14, 0, 4, 0, 0, 46, 46, 46, 46, 0, 0, 1, 0, 14],
            // [14, 0, 8, 0, 0, 19, 0, 20, 0, 0, 0, 0, 0, 14],
            // [14, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14],
            // [14, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 14],
            // [14, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 26, 0, 14],
            // [14, 0, 0, 1, 0, 1, 28, 0, 1, 0, 0, 0, 0, 14],
            // [14, 0, 4, 0, 0, 1, 1, 1, 1, 0, 0, 4, 0, 14],
            // [14, 0, 39, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 14],
            // [14, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 14],
            // [14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14],
            // [11, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12],
            [9, 13, 13, 35, 13, 13, 13, 42, 13, 13, 13, 13, 13, 10],
            [14, 0, 21, 0, 0, 0, 0, 0, 0,0, 0, 21, 20, 14],
            [14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14],
            [14, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0, 0, 14],
            [14, 21, 0, 0, 0, 19, 0, 0, 0, 0, 0, 0, 0, 14],
            [14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14],
            [14, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 14],
            [14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14],
            [11, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 12],
        ],
        id: 0,
        name: "",
        orderNum: 0,
        description: "",
        difficulty: 0,
        type: 0,
        nextLevel: 0,
        status: 0
    } //关卡详情
    videoAd=null //激励视频广告
    mapWidth: number = 0 //地图宽度
    mapHeight: number = 0 //地图高度
    low_level: number = 0
    height: number = 150
    width: number = 150
    position: number = this.height * 0.6
    cameraBoundary: Vec3 = new Vec3(0, 0, 0) //记录最右边和最下边的坐标
    socket_number:number=0
    async_scence:Array<{type:string,node:string,player}>=[]

    reset() {
        this.disbledButton = false
        this.mapWidth = 0 //地图宽度
        this.mapHeight = 0 //地图高度
        this.fraction = 0
        this.player = []
        this.enemyList = []
        this.cameraBoundary = new Vec3(0, 0, 0)
    }
}